#
# $Header: /mount/cvs-repository/Aligner/lib/perl/packs/exargs.pm,v 1.1 2007/10/08 09:26:04 schweitz Exp $
#
# this little package will parse arguments of the form key=value, and
# set the perl variable "$key" to value value.  it will remove these
# arguments from the command line and leave the following args unchanged.

# First we set the PATH environment variable

package exargs;

require "/speech/db/jpn/recogjp/share/lib/setenv.pl";
#$speech_dir = $ENV{'SPEECH_DIR'};
#$speech_dir = "/u/drspeech" if ($speech_dir eq "");
#$speech_shbindir = $ENV{'SPEECH_SHBINDIR'};
#$speech_shbindir = "$speech_dir/share/bin" if $speech_shbindir eq "";
#$speech_arch = $ENV{'SPEECH_ARCH'};
#if ($speech_arch eq "") {
#    $speech_arch = `$speech_shbindir/speech_arch`;
#    chop($speech_arch);
#}
#$speech_bindir = $ENV{'SPEECH_BINDIR'};
#$speech_bindir = "$speech_dir/$speech_arch/bin" if $speech_bindir eq "";
#
#$ENV{'PATH'} = "$speech_bindir:$speech_shbindir"
#  . ":/usr/local/bin:/usr/ucb:/usr/bin:/bin";


sub exargs {

  $exargs_argsset = "";

  while ($#ARGV > -1) {
    if (($key,$value) = ($ARGV[0] =~ /(.*[^\\])=(.*)/)) {
      $key =~ s/\\=/=/g;	# unescape =
      $value =~ s/\\=/=/g;
      #if ($value ne "") {
      $foos =  '$' . "$key = " . '$' . "value ;" ;
      eval $foos;
      print "\$$key = $value\n" if &exargs_booltrue($debugargs);
      $exargs_argsset .= "$key ";
      #}
      undef $key;
      undef $value;
      shift @ARGV;
    }
    else { last; }
  }
}

sub exargs_booltrue{
    # return true if the string argument should be true
    local($_) = $_[0];		# put first arg into default variable
    /^t/i && return 1;
    /^y/i && return 1;
    /1/ && return 1;
    return 0;
}

1;   # make require happy....
